//-------------------------------------------------------------------
//	Copyright (c) 2010-2012  Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_SOUND_SOURCE_H
#define _UX_SOUND_SOURCE_H

#include <Includes.h>

namespace Engine
{
namespace Resources
{

	//
	// Sound Source
	//

	struct TSoundSource
	{
		binary_buffer_t			aData;
		uint					uFreq;
		float					fGain,
								fPitch;
		al_format::type			eFormat;
		e_sound_format::type	eIntFormat;
		bool					bLooping;
		///
		TSoundSource():
			uFreq(0), eFormat(al_format::UNKNOWN), eIntFormat(e_sound_format::UNKNOWN),
			fGain(0.f), fPitch(0.f), bLooping(false) {}

		void Clear()
		{
			aData.Clear();
			fGain		= 0.f;
			fPitch		= 0.f;
			bLooping	= false;
			uFreq		= 0;
			eFormat		= al_format::UNKNOWN;
			eIntFormat	= e_sound_format::UNKNOWN;
		}
	};



	//
	// Streamed Sound
	//

	struct TStreamedSound
	{
		struct TSoundBufferInfo
		{
			uint	uSize,		// buffer size
					uOffset;	// offset of begin of file
			///
			TSoundBufferInfo(): uSize(0), uOffset(0) {}
		};

		typedef array< TSoundBufferInfo >	sndbufinfo_t;

		IFilePtr				pFile;
		sndbufinfo_t			aBufSizes;
		uint					uFreq;
		float					fGain,
								fPitch;
		al_format::type			eFormat;
		e_sound_format::type	eIntFormat;
		bool					bLooping;
		///
		TStreamedSound():
			eFormat(al_format::UNKNOWN), uFreq(0), eIntFormat(e_sound_format::UNKNOWN),
			fGain(0.f), fPitch(0.f), bLooping(false) {}
	
		void Clear()
		{
			aBufSizes.Clear();
			pFile		= nullptr;
			fGain		= 0.f;
			fPitch		= 0.f;
			bLooping	= false;
			uFreq		= 0;
			eFormat		= al_format::UNKNOWN;
			eIntFormat	= e_sound_format::UNKNOWN;
		}
	};


	//
	// Streamed Sound Source (for save only)
	//

	struct TStreamedSource
	{
		binary_buffer_t			aData;		// sound data
		uint32_array_t			aSizes;		// size of sound buffer blok
		uint					uFreq;
		float					fGain,
								fPitch;
		al_format::type			eFormat;
		e_sound_format::type	eIntFormat;
		bool					bLooping;
		///
		TStreamedSource():
			eFormat(al_format::UNKNOWN), uFreq(0), eIntFormat(e_sound_format::UNKNOWN),
			fGain(0.f), fPitch(0.f), bLooping(false) {}

		void Clear()
		{
			aData.Clear();
			aSizes.Clear();
			fGain		= 0.f;
			fPitch		= 0.f;
			bLooping	= false;
			uFreq		= 0;
			eFormat		= al_format::UNKNOWN;
			eIntFormat	= e_sound_format::UNKNOWN;
		}
	};



	struct _EXPORT_ Sound
	{
		static bool GetFormat(al_format::type &eFormat, uint8 uChannels, uint8 uBitPerSample, bool bRear = false);
		static bool GetFormat(ALenum eALFormat, al_format::type &eFormat);

		static bool GetALFormat(ALenum &eFormat, uint8 uChannels, uint8 uBitPerSample, bool bRear = false);
		static bool GetALFormat(al_format::type eFormat, ALenum &eALFormat);

		static uint GetChannels(al_format::type eFormat);
		static uint GetBitPerSample(al_format::type eFormat);
	};

//-------------------------------------------------------------------

}	// Resources
}	// Engine

#endif	// _UX_SOUND_SOURCE_H